package com.xian.wsim.controller;

import com.xian.wsim.service.UserOnlineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user-status")
public class UserController {

    @Autowired
    private UserOnlineService userOnlineService;

    @PostMapping("/{userId}/online")
    @CrossOrigin(origins = "*")
    public void setUserOnline(@PathVariable Long userId) {
        userOnlineService.setUserOnline(userId);
    }

    @PostMapping("/{userId}/offline")
    @CrossOrigin(origins = "*")
    public void setUserOffline(@PathVariable Long userId) {
        userOnlineService.setUserOffline(userId);
    }

    @GetMapping("/{userId}/isOnline")
    @CrossOrigin(origins = "*")
    public boolean isUserOnline(@PathVariable Long userId) {
        return userOnlineService.isUserOnline(userId);
    }
}